//
// Created by yangchao on 2022/7/14.
// 225. 用队列实现栈: https://leetcode.cn/problems/implement-stack-using-queues/
//
#include <queue>
using namespace std;
class MyStack {
public:
    queue<int> qe1;
    queue<int> qe2;

    MyStack() {

    }

    void push(int x) {
        qe1.push(x);
    }

    int pop() {
        int size = qe1.size();
        size--;
        while (size--) {
            qe2.push(qe1.front());
            qe1.pop();
        }
        int res = qe1.front();
        qe1.pop();
        qe1 = qe2;
        while (!qe2.empty()) {
            qe2.pop();
        }
        return res;
    }

    int top() {
        return qe1.back();
    }

    bool empty() {
        return qe1.empty();
    }
};

